<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/8/4
 * Time: 15:35
 */
namespace app\franchisee\controller;
use think\Db;
class Order extends Base {
    /**
     * 异地登录验证
     * @return string
     */
//    public function __construct()
//    {
//        extract(input());
//        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
//        if($auth == 112){
//            echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
//            exit;
//        }elseif($auth == 110){
//            echo json_encode(['status' => 302, 'msg' => $this->frost]);
//            exit;
//        }
//    }
    //搜索
    public function index(){
        extract(input());
        $page = input('param.page')?input('param.page'):1;
        $num = 10;
        $limit = ($page-1)*$num;
        $keyword = input('param.keyword');
        $res = array();
        if($keyword==''){
            return json(['status'=>200,'msg'=>$res]);
        }else{
            $map['district'] = array('like',"%$keyword%");
            $district_id= Db::table('up_area')->where($map)->column('district_id');
            if(count($district_id)>0){
             $where['a.order_go_sheng|a.order_go_shi|a.order_to_sheng|a.order_to_shi'] = array('IN',$district_id);
          }else{
                return json(['status'=>200,'msg'=>$res]);
            }
        }
        $where['a.order_type'] = array('not in',array(3,4));
        $where['a.order_status'] = array('>',1);
        $res = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
            ->limit($limit,$num)
            ->where($where)
            ->order('a.order_fb_time desc')
            ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
            ->select();
        return json(['status' => 200, 'msg' => $res]);
    }

    //订单列表
    public function orderList(){
        extract(input());
        $type = input('param.type');//1询价  2进行中  3待确认  4代付款 5已完成  6全部订单
        $page = input('param.page')?input('param.page'):1;
        $num = 10;
        $limit = ($page-1)*$num;
        $where['a.order_jms_user'] = $user_id;
        if($type==1){//询价
            $where['a.order_type'] = 1;
            $where['a.order_status'] = array('IN',array(1,2,3,4));
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==2){//进行中
            $where['a.order_status'] = array('IN',array(5,6));
            $where['a.order_type'] = 2;
            $map['a.order_type'] = 1;
            $map['a.order_status'] =array('IN',array(5,6));
            $map['a.order_true'] =1;
            $map['a.order_jms_user'] = $user_id;
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where(function ($query) use($where){
                    $query->where($where);
                })
                ->whereOr(function ($query) use($map){
                    $query->where($map);
                })
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==3){//待付款
            $where['a.order_type'] = array('not in',array(3,4));
            $where['a.order_status'] = 7;
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==4){//已完成
            $where['a.order_type'] = array('not in',array(3,4));
            $where['a.order_status'] = array('IN',array(8,9));
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==5){//全部订单
            $where['a.order_type'] = array('not in',array(3,4));
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')

                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==6){//发布中
            $where['a.order_type'] = 2;
            $where['a.order_status'] = array('IN',array(1,2,3,4));
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user','left')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }
    }
    public function orderListNum(){
        extract(input());
        //询价单
        $where['a.order_jms_user'] = $user_id;
        $where['a.order_type'] = 1;
        $where['a.order_status'] = array('IN',array(1,2,3,4));
        $num = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
            ->where($where)
            ->count();
        //进行中
        $where1['a.order_status'] = array('IN',array(5,6));
        $where1['a.order_type'] = 2;
        $where1['a.order_jms_user'] = $user_id;
        $map['a.order_type'] = 1;
        $map['a.order_status'] =array('IN',array(5,6));
        $map['a.order_true'] =1;
        $map['a.order_jms_user'] = $user_id;
        $num1 = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
            ->where(function ($query) use($where1){
                $query->where($where1);
            })
            ->whereOr(function ($query) use($map){
                $query->where($map);
            })
            ->count();
        //待付款
        $where2['a.order_type'] = array('not in',array(3,4));
        $where2['a.order_status'] = 7;
        $where2['a.order_jms_user'] = $user_id;
        $num2 = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
            ->where($where2)
            ->count();
        //发布中
        $where3['a.order_type'] = 2;
        $where3['a.order_status'] = array('IN',array(1,2,3,4));
        $where3['a.order_jms_user'] = $user_id;
        $num3 = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user','left')
            ->where($where3)
            ->count();
        $res['xjd'] = $num;
        $res['jxz'] = $num1;
        $res['dfk'] = $num2;
        $res['fbz'] = $num3;
        return json(['status' => 200, 'msg' => $res]);
    }
    //扭转的货源
    public function orderList1(){
        extract(input());
        $type = input('param.type');//1询价  2发布货源
        $page = input('param.page')?input('param.page'):1;
        $num = 10;
        $limit = ($page-1)*$num;
        $where['a.order_jms_user'] = $user_id;
        if($type==1){//询价
            $where['a.order_type'] = 1;
            $where['a.order_status'] = array('IN',array(1));
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==2){//正常单
            $where['a.order_type'] = 2;
            $where['a.order_status'] = array('IN',array(1));
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user','left')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }
    }

    public function orderList1Num(){
        extract(input());
        //询价
        $where['a.order_type'] = 1;
        $where['a.order_jms_user'] = $user_id;
        $where['a.order_status'] = array('IN',array(1));

        $num = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
            ->where($where)
            ->count();
        $where1['a.order_type'] = 2;
        $where1['a.order_status'] = array('IN',array(1));
        $where1['a.order_jms_user'] = $user_id;
        $num1 = Db::table('up_order')->alias('a')
            ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
            ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
            ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
            ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
            ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
            ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
            ->join('up_u_user uuu','uuu.user_id = a.order_qy_user','left')
            ->where($where1)
            ->count();
        $res['xjd'] = $num;
        $res['zcd'] = $num1;
        return json(['status' => 200, 'msg' => $res]);
    }
    //已发布的货源
    public function orderList2(){
        extract(input());
        $type = input('param.type');//1询价  2发布货源
        $page = input('param.page')?input('param.page'):1;
        $num = 10;
        $limit = ($page-1)*$num;
        $where['a.order_jms_user'] = $user_id;
        if($type==1){//询价
            $where['a.order_type'] = 1;
            $where['a.order_status'] = array('>',2);
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }elseif ($type==2){//发布中
            $where['a.order_type'] = 2;
            $where['a.order_status'] = array('>',2);
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_car_zxlx ucz','ucz.zxlx_id = a.zxlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user','left')
                ->limit($limit,$num)
                ->where($where)
                ->order('a.order_fb_time desc')
                ->field('a.order_num,a.order_true,ucz.zxlx_name,a.order_goods_m,a.order_type,a.order_status,a.order_fb_time,a.cx_id as cx_name,uch.hwlx_name,
            a.order_cc,a.order_goods_ton,a.order_zc_time,a.order_go_lon,a.order_go_lat,a.order_to_lon,a.order_to_lat,a.order_zcsj_time,
            a.order_id,ua.district as go_sheng,ua1.district as go_shi,
            ua2.district as to_sheng,ua3.district as to_shi,uuu.user_image,uuu.user_phone,uuu.user_username,uuu.user_real_name')
                ->select();
            return json(['status' => 200, 'msg' => $res]);
        }
    }
    //订单详情
    public function detailOrder(){
        extract(input());
        $id = input('param.order_id');
        $where['a.order_id'] = $id;
        $info = Db::table('up_order')->alias('a')->where($where)->field('order_type')->find();
        if($info['order_type']==1){//询价单
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua4','ua4.district_id = a.order_go_qu','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->join('up_area ua5','ua5.district_id = a.order_to_qu','left')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user','left')
                ->join('up_car_zxlx ucz' ,'ucz.zxlx_id = a.zxlx_id','left')
                ->where($where)
                ->field('a.*,ua.district as go_sheng,ua1.district as go_shi,ua4.district as go_qu,
                        ua2.district as to_sheng,ua3.district as to_shi,ua5.district as to_qu,
                        uuu.user_phone,uuu.user_username,uuu.user_real_name,uuu.user_username
                        ,ucz.zxlx_name,uch.hwlx_name')
                ->find();
        }else{
            $res = Db::table('up_order')->alias('a')
                ->join('up_car_hwlx uch','uch.hwlx_id = a.hwlx_id','left')
                ->join('up_area ua','ua.district_id = a.order_go_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.order_go_shi','left')
                ->join('up_area ua4','ua4.district_id = a.order_go_qu','left')
                ->join('up_area ua2','ua2.district_id = a.order_to_sheng','left')
                ->join('up_area ua3','ua3.district_id = a.order_to_shi','left')
                ->join('up_area ua5','ua5.district_id = a.order_to_qu','left')
                ->join('up_u_user uuu','uuu.user_id = a.order_qy_user')
                ->join('up_car_zxlx ucz' ,'ucz.zxlx_id = a.zxlx_id','left')
                ->where($where)
                ->field('a.*,ua.district as go_sheng,ua1.district as go_shi,ua4.district as go_qu,
                        ua2.district as to_sheng,ua3.district as to_shi,ua5.district as to_qu,
                        uuu.user_phone,uuu.user_username,uuu.user_real_name,uuu.user_username
                        ,ucz.zxlx_name,uch.hwlx_name')
                ->find();
        }
        $map['order_id'] = $id;
        $info = Db::table('up_order_dot')->field('dot_id as id,dot_lon as lon,dot_lat as lat')->where($map)->select();
        $res['info'] = $info;
        return json(['status' => 200, 'msg' => $res]);
    }
    public function index1(){
        //车长
        $where['is_status'] = 1;
        $where['is_del'] = 1;
        $res = Db::table('up_car_cclb')->field('cclb_id,cclb_name')->where($where)->select();
        //车型
        $where1['is_status'] = 1;
        $where1['is_del'] = 1;
        $res1 = Db::table('up_car_cx')->field('cx_id,cx_name')->where($where1)->select();
        //货物类型
        $where2['is_status'] = 1;
        $where2['is_del'] = 1;
        $res2 = Db::table('up_car_hwlx')->field('hwlx_id,hwlx_name')->where($where2)->select();
        //装修类型
        $where3['is_status'] = 1;
        $where3['is_del'] = 1;
        $res3 = Db::table('up_car_zxlx')->field('zxlx_id,zxlx_name')->where($where3)->select();
        $list['cc'] = $res;
        $list['cx'] = $res1;
        $list['hwlx'] = $res2;
        $list['zx'] = $res3;
        return json(['status' => 200, 'msg' => $list]);
    }



    //编辑订单
    public function updateOrder(){
        extract(input());
        $order_id = input('param.order_id');
        //出发地
        $order_go_sheng = input('param.order_go_sheng');//出发省
        $order_go_shi = input('param.order_go_shi');
        $order_go_qu = input('param.order_go_qu');
        $order_go_address = input('param.order_go_address');
        $order_go_lon = input('param.order_go_lon');
        $order_go_lat = input('param.order_go_lat');
        //目的地
        $order_to_sheng = input('param.order_to_sheng');
        $order_to_shi = input('param.order_to_shi');
        $order_to_qu = input('param.order_to_qu');
        $order_to_address = input('param.order_to_address');
        $order_to_lon = input('param.order_to_lon');
        $order_to_lat = input('param.order_to_lat');
        //货物
        $order_goods_name = input('param.order_goods_name');
        $order_goods_ton = input('param.order_goods_ton');
        $order_goods_m = input('param.order_goods_m');
        $order_freight = input('param.order_freight');
        $order_zf_type = input('param.order_zf_type');
        $order_zc_time = input('param.order_zc_time');
        $zxlx_id = input('param.zxlx_id');
        $cx_id = input('param.cx_id');
        $order_cc = input('param.order_cc');
        $hwlx_id = input('param.hwlx_id');
        $order_intro = input('param.order_intro');
        $order_goods_img = input('param.order_goods_img');
        $data['order_go_sheng'] = $order_go_sheng;
        $data['order_go_shi'] = $order_go_shi;
        $data['order_go_qu'] = $order_go_qu;
        $data['order_go_address'] = $order_go_address;
        $data['order_go_lon'] = $order_go_lon;
        $data['order_go_lat'] = $order_go_lat;
        $data['order_to_sheng'] = $order_to_sheng;
        $data['order_to_shi'] = $order_to_shi;
        $data['order_to_qu'] = $order_to_qu;
        $data['order_to_address'] = $order_to_address;
        $data['order_to_lon'] = $order_to_lon;
        $data['order_to_lat'] = $order_to_lat;
        $data['order_goods_name'] = $order_goods_name;
        $data['order_goods_ton'] = $order_goods_ton;
        $data['order_goods_m'] = $order_goods_m;
        $data['order_freight'] = $order_freight;
        $data['order_zf_type'] = $order_zf_type;
        $data['order_zc_time'] = $order_zc_time;
        $data['zxlx_id'] = $zxlx_id;
        $data['cx_id'] = $cx_id;
        $data['order_cc'] = $order_cc;
        $data['hwlx_id'] = $hwlx_id;
        $data['order_intro'] = $order_intro;
        $data['order_goods_img'] = $order_goods_img;
        $data['order_status'] = 2;
        Db::table('up_order')->where('order_id',$order_id)->update($data);
        //查询出发地,目的地
        $go_sheng =Db::table('up_area')->where('district_id',$order_go_sheng)->value('district');
        $to_sheng = Db::table('up_area')->where('district_id',$order_to_sheng)->value('district');
        $user_company_name = Db::table('up_u_user')->where('user_id',$user_id)->value('user_company_name');
        //插入消息表
        $list= Db::table('up_route')
            ->where(function ($query) {
                $query->where('go_status', -1)
                    ->where('to_status', -1);
            })
            ->whereOr(function ($query) use($order_to_sheng){
                $query->where('go_status', -1)
                    ->where('to_status', 'neq',-1)
                    ->where('to_sheng', $order_to_sheng);
            })
            ->whereOr(function ($query) use($order_go_sheng){
                $query->where('go_status', 'neq',-1)
                    ->where('to_status',-1)
                    ->where('go_sheng', $order_go_sheng);
            })->whereOr(function ($query) use($order_to_sheng,$order_go_sheng){
                $query->where('go_status', 'neq',-1)
                    ->where('to_status','neq',-1)
                    ->where('go_sheng', $order_go_sheng)
                    ->where('to_sheng', $order_to_sheng);
            })
            ->distinct('true')
            ->column('user_id');
        //插入消息表
        $dataList['n_title'] = $user_company_name.'发布了订单从'.$go_sheng.'--到'.$to_sheng.'，请尽快处理';
        $dataList['n_type'] =  2;
        $dataList['n_notice_type'] = 2;
        $dataList['n_user_id'] = ','.implode(',',$list).',';
        $dataList['n_read'] = ',0,';
        $dataList['n_delete'] = ',0,';
        $dataList['n_time'] = date('Y-m-d H:i:s');
        $dataList['n_status'] = 2;
        Db::table('up_notice')->insertGetId($dataList);
        //推送
        $lists = [];
        foreach ($list as $key=>$vo){
            $v = (string)$vo;
            array_push($lists, $v);
        }

        $code=2;
        $str = array('msg'=>$user_company_name.'发布了订单从'.$go_sheng.'--到'.$to_sheng.'，请尽快处理','type'=>1,'order_id'=>$order_id);
        $str1 = $user_company_name.'发布了订单从'.$go_sheng.'--到'.$to_sheng.'，请尽快处理';
        //推送司机
        try{
            $this->Jpush1(1, $list, $str1, $str,$code);
        }catch(\Exception $e){

        }
        return json(['status'=>200,'msg'=>"编辑成功"]);
    }
    //电子协议详情
    public function dzxyOrderDetail(){
        extract(input());
        $order_id = input('param.order_id');
        $res = Db::table('up_order')->where('order_id',$order_id)
            ->field('order_freight,order_id,order_dzxy_freight,order_dzxy_yf')->find();
        return json(['status'=>200,'msg'=>$res]);
    }
    //正常单- 电子协议
    public function dzxyOrder(){
        extract(input());
        $order_id = input('param.order_id');
        $type = input('param.type');
        $list = Db::table('up_order')->where('order_id',$order_id)->find();
        $data1 = Db::table('up_u_user')->where('user_id',$list['order_jms_user'])->find();
        $data2 = Db::table('up_u_user')->where('user_id',$list['order_dirver_user'])->find();

        //查询地区
        $go_sheng = Db::table('up_area')->where('district_id',$list['order_go_sheng'])->value('district');
        $go_shi = Db::table('up_area')->where('district_id',$list['order_go_shi'])->value('district');
        $to_sheng = Db::table('up_area')->where('district_id',$list['order_to_sheng'])->value('district');
        $to_shi = Db::table('up_area')->where('district_id',$list['order_to_shi'])->value('district');
        if($type==1){//同意
         $res = Db::table('up_order')->where('order_id',$order_id)->setField('order_status',5);
            //插入消息表
            $dataList['n_title'] = '您的电子协议已被加盟商确认，请尽快赶往装货地点装货';
            $dataList['n_type'] =  2;
            $dataList['n_notice_type'] = 2;
            $dataList['n_user_id'] = ','.$list['order_dirver_user'].',';
            $dataList['n_read'] = ',0,';
            $dataList['n_delete'] = ',0,';
            $dataList['n_time'] = date('Y-m-d H:i:s');
            $dataList['n_status'] = 2;
            Db::table('up_notice')->insertGetId($dataList);
             YzxSms($data1['user_company_name'], $data2['user_phone'], '',562125);//发送验证码

        }elseif ($type==2){//拒绝
            $data['order_dirver_user'] = '';
            $data['order_zc_goods_img'] = '';
            $data['order_xh_goods_img'] = '';
            $data['order_status'] = 2;
            $data['order_dzxy_freight'] = '';
            $data['order_dzxy_yf'] = '';
            $res =Db::table('up_order')->where('order_id',$order_id)->update($data);

            $dataList['n_title'] = '您的电子协议已被加盟商拒绝，订单取消';
            $dataList['n_type'] =  2;
            $dataList['n_notice_type'] = 2;
            $dataList['n_user_id'] = ','.$list['order_dirver_user'].',';
            $dataList['n_read'] = ',0,';
            $dataList['n_delete'] = ',0,';
            $dataList['n_time'] = date('Y-m-d H:i:s');
            $dataList['n_status'] = 2;
            Db::table('up_notice')->insertGetId($dataList);
            YzxSms($data1['user_company_name'], $data2['user_phone'], '',562126);//发送验证码
            //推送
//            $lists = [];
            $v = (string)$list['order_dirver_user'];
//            array_push($lists, $v);

            $code=2;
            $str = array('msg'=>'您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请联系加盟商','type'=>1,'order_id'=>$order_id);
            $str1 = '您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请联系加盟商';
            //推送司机
            try{
                $this->Jpush1(1, $v, $str1, $str,$code);
            }catch(\Exception $e){

            }

            //定金
            $order_number = date('YmdHis') . str_pad(mt_rand(1, 99999999), 6, '0', STR_PAD_LEFT).$list['order_dirver_user'];
            $data4['user_id'] = $list['order_dirver_user'];
            $data4['balance_type'] = 2;
            $data4['balance_time'] = date('Y-m-d H:i:s');
            $data4['balance_title'] = $go_sheng.$go_shi.'--'.$to_sheng.$to_shi.'订单定金返还';
            $data4['balance_num'] = $order_number;
            $data4['balance_price'] = $list['order_dzxy_yf'];
            $data4['balance_status'] = 2;
            $data4['balance_jia_jian'] = 1;
            Db::table('up_user_balance')->insertGetId($data4);
            Db::table('up_u_user')->where('user_id',$list['order_dirver_user'])->setInc('user_balance',$list['order_dzxy_yf']);

            //插入加盟商钱包明细
            $order_number1 = date('YmdHis') . str_pad(mt_rand(1, 99999999), 6, '0', STR_PAD_LEFT).$list['order_jms_user'];
            $user_real_name1 = Db::table('up_u_user')
                ->where('user_id',$list['order_dirver_user'])
                ->value("user_real_name");
            //定金
            $data5['user_id'] = $list['order_jms_user'];
            $data5['balance_type'] = 2;
            $data5['balance_time'] = date('Y-m-d H:i:s');
            $data5['balance_title'] = $go_sheng.$go_shi.'--'.$to_sheng.$to_shi.'订单定金返还司机'.($user_real_name1);
            $data5['balance_num'] = $order_number1;
            $data5['balance_price'] = $list['order_dzxy_yf'];
            $data5['balance_status'] = 2;
            $data5['balance_jia_jian'] = 2;
            Db::table('up_user_balance')->insertGetId($data5);
            Db::table('up_u_user')->where('user_id',$list['order_jms_user'])->setDec('user_balance',$list['order_dzxy_yf']);        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>200,'msg'=>'操作失败']);
        }
    }

    //电子协议-询价单
    public function dzxyOrder1(){
        extract(input());
        $order_id = input('param.order_id');
        $type = input('param.type');
        $list = Db::table('up_order')->where('order_id',$order_id)->find();
        $data1 = Db::table('up_u_user')->where('user_id',$list['order_jms_user'])->find();
        $data2 = Db::table('up_u_user')->where('user_id',$list['order_qy_user'])->find();
        $go_sheng = Db::table('up_area')->where('district_id',$list['order_go_sheng'])->value('district');
        $to_sheng = Db::table('up_area')->where('district_id',$list['order_to_sheng'])->value('district');
        if($type==1){//同意
            $data['order_freight'] = input('param.money');
            $data['send_date'] = date('Y-m-d H:i:s');
            $data['order_true'] = 2;
             Db::table('up_order')->where('order_id',$order_id)->update($data);
            //插入消息表
            $dataList['n_title'] = '您的询价单已被加盟商确认，请尽快确认价格';
            $dataList['n_type'] =  2;
            $dataList['n_notice_type'] = 2;
            $dataList['n_user_id'] = ','.$list['order_qy_user'].',';
            $dataList['n_read'] = ',0,';
            $dataList['n_delete'] = ',0,';
            $dataList['n_time'] = date('Y-m-d H:i:s');
            $dataList['n_status'] = 2;
            $res = Db::table('up_notice')->insertGetId($dataList);
            YzxSms($data1['user_company_name'], $data2['user_phone'], '',566454);//发送验证码

        }elseif ($type==2){//拒绝
            //推送
//            $v = (string)$list['order_dirver_user'];
//
//            $code=2;
//            $str = array('msg'=>'您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请联系加盟商','type'=>1,'order_id'=>$order_id);
//            $str1 = '您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请联系加盟商';
//            //推送司机
//            try{
//                $this->Jpush1(1, $v, $str1, $str,$code);
//            }catch(\Exception $e){
//
//            }
            $data['order_dirver_user'] = '';
            $data['order_zc_goods_img'] = '';
            $data['order_xh_goods_img'] = '';
            $data['order_status'] = 2;
            $data['order_dzxy_freight'] = '';
            $data['order_dzxy_yf'] = '';
            $res =Db::table('up_order')->where('order_id',$order_id)->update($data);

            $dataList['n_title'] = '您的电子协议已被加盟商拒绝，订单取消';
            $dataList['n_type'] =  2;
            $dataList['n_notice_type'] = 2;
            $dataList['n_user_id'] = ','.$list['order_dirver_user'].',';
            $dataList['n_read'] = ',0,';
            $dataList['n_delete'] = ',0,';
            $dataList['n_time'] = date('Y-m-d H:i:s');
            $dataList['n_status'] = 2;
            Db::table('up_notice')->insertGetId($dataList);
            YzxSms($data1['user_company_name']?$data1['user_company_name']:'平台', $data2['user_phone'], '',562126);//发送验证码
            //推送
//            $lists = [];
            $v = (string)$list['order_dirver_user'];
//            array_push($lists, $v);

            $code=2;
            $str = array('msg'=>'您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请联系加盟商','type'=>1,'order_id'=>$order_id);
            $str1 = '您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请联系加盟商';
            //推送司机
            try{
                $this->Jpush1(1, $v, $str1, $str,$code);
            }catch(\Exception $e){

            }
            //查询地区
            $go_sheng = Db::table('up_area')->where('district_id',$list['order_go_sheng'])->value('district');
            $go_shi = Db::table('up_area')->where('district_id',$list['order_go_shi'])->value('district');
            $to_sheng = Db::table('up_area')->where('district_id',$list['order_to_sheng'])->value('district');
            $to_shi = Db::table('up_area')->where('district_id',$list['order_to_shi'])->value('district');
            //定金
            $order_number = date('YmdHis') . str_pad(mt_rand(1, 99999999), 6, '0', STR_PAD_LEFT).$list['order_dirver_user'];
            $data4['user_id'] = $list['order_dirver_user'];
            $data4['balance_type'] = 2;
            $data4['balance_time'] = date('Y-m-d H:i:s');
            $data4['balance_title'] = $go_sheng.$go_shi.'--'.$to_sheng.$to_shi.'订单定金返还';
            $data4['balance_num'] = $order_number;
            $data4['balance_price'] = $list['order_dzxy_yf'];
            $data4['balance_status'] = 2;
            $data4['balance_jia_jian'] = 1;
            $data4['balance_xs'] = 1;

            Db::table('up_user_balance')->insertGetId($data4);
            Db::table('up_u_user')->where('user_id',$list['order_dirver_user'])->setInc('user_balance',$list['order_dzxy_yf']);

            //插入加盟商钱包明细
            $order_number1 = date('YmdHis') . str_pad(mt_rand(1, 99999999), 6, '0', STR_PAD_LEFT).$list['order_jms_user'];
            $user_real_name1 = Db::table('up_u_user')
                ->where('user_id',$list['order_dirver_user'])
                ->value("user_real_name");
            //定金
            $data5['user_id'] = $list['order_jms_user'];
            $data5['balance_type'] = 2;
            $data5['balance_time'] = date('Y-m-d H:i:s');
            $data5['balance_title'] = $go_sheng.$go_shi.'--'.$to_sheng.$to_shi.'订单定金返还司机'.($user_real_name1);
            $data5['balance_num'] = $order_number1;
            $data5['balance_price'] = $list['order_dzxy_yf'];
            $data5['balance_status'] = 2;
            $data5['balance_jia_jian'] = 2;
            $data5['balance_xs'] = 2;

            Db::table('up_user_balance')->insertGetId($data5);
            Db::table('up_u_user')->where('user_id',$list['order_jms_user'])->setDec('user_balance',$list['order_dzxy_yf']);

        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>200,'msg'=>'操作失败']);
        }
    }
    //余额支付
    public function pay(){
        extract(input());
        $order_id = input('param.order_id');
        $password = input('param.password');
        $userInfo = Db::table('up_u_user')->where('user_id',$user_id)->field('user_zf_password,user_balance')->find();

        if($password==''){
            return json(['status'=>100,'msg'=>"支付密码不能为空"]);
        }
        if($password!=$userInfo['user_zf_password']){
            return json(['status'=>100,'msg'=>"支付密码输入错误"]);
        }
        $money1 = Db::table('up_order')->where('order_id',$order_id)->field('order_dzxy_freight')->find();
        if($money1['order_dzxy_freight']>$userInfo['user_balance']){
            return json(['status'=>100,'msg'=>"余额不足,无法完成支付"]);
        }
        Db::startTrans();
        try{
            $info = Db::table('up_order')->where('order_id',$order_id)->find();
            if($info['order_status'] == 7){
                //更新订单状态
                $dataOrder['order_paytime1'] = date('Y-m-d H:i:s');//支付时间
                $dataOrder['order_status'] = 8;
                Db::table('up_order')->where('order_id',$order_id)->update($dataOrder);
                //查询地区
                $go_sheng = Db::table('up_area')->where('district_id',$info['order_go_sheng'])->value('district');
                $go_shi = Db::table('up_area')->where('district_id',$info['order_go_shi'])->value('district');
                $to_sheng = Db::table('up_area')->where('district_id',$info['order_to_sheng'])->value('district');
                $to_shi = Db::table('up_area')->where('district_id',$info['order_to_shi'])->value('district');
                //插入order_detail表
                $listData['order_detail_go_sheng'] = $go_sheng;
                $listData['order_detail_go_shi'] = $go_shi;
                $listData['order_detail_to_sheng'] = $to_sheng;
                $listData['order_detail_to_shi'] = $to_shi;
                $listData['order_detail_incon'] = '';
                $listData['user_id'] = $info['order_jms_user'];
                $listData['order_detail_price'] = $info['order_freight'];
                $listData['order_id'] = $info['order_id'];
                $listData['order_detail_type'] = 1;
                $listData['order_detail_ymd'] = $info['order_fb_ymr'];
                $listData['oder_detail_ym'] = $info['order_fb_ym'];
                Db::table('up_order_detail')->insertGetId($listData);
                //司机成本
                $listData1['order_detail_go_sheng'] = $go_sheng;
                $listData1['order_detail_go_shi'] = $go_shi;
                $listData1['order_detail_to_sheng'] = $to_sheng;
                $listData1['order_detail_to_shi'] = $to_shi;
                $listData1['order_detail_incon'] = '司机成本';
                $listData1['user_id'] = $info['order_jms_user'];
                $listData1['order_detail_price'] = $info['order_dzxy_freight'];
                $listData1['order_id'] = $info['order_id'];
                $listData1['order_detail_type'] = 2;
                $listData1['order_detail_ymd'] = $info['order_fb_ymr'];
                $listData1['oder_detail_ym'] = $info['order_fb_ym'];
                Db::table('up_order_detail')->insertGetId($listData1);
                //进税项
                $listData2['order_detail_go_sheng'] = $go_sheng;
                $listData2['order_detail_go_shi'] = $go_shi;
                $listData2['order_detail_to_sheng'] = $to_sheng;
                $listData2['order_detail_to_shi'] = $to_shi;
                $listData2['order_detail_incon'] = '进税项';
                $listData2['user_id'] = $info['order_jms_user'];
                $listData2['order_detail_price'] = ($info['order_freight']/1.09)*0.09;
                $listData2['order_id'] = $info['order_id'];
                $listData2['order_detail_type'] = 2;
                $listData2['order_detail_ymd'] = $info['order_fb_ymr'];
                $listData2['oder_detail_ym'] = $info['order_fb_ym'];
                Db::table('up_order_detail')->insertGetId($listData2);
                //平台抽成
                $price3 = 0;
                if($info['order_freight']<30000){
                    $price3 = $info['order_freight']*0.0358;
                }elseif ($info['order_freight']>=30000&&$info['order_freight']<300000){
                    $price3 = $info['order_freight']*0.0258;
                }elseif ($info['order_freight']>=300000){
                    $price3 = $info['order_freight']*0.0198;
                }
                $listData3['order_detail_go_sheng'] = $go_sheng;
                $listData3['order_detail_go_shi'] = $go_shi;
                $listData3['order_detail_to_sheng'] = $to_sheng;
                $listData3['order_detail_to_shi'] = $to_shi;
                $listData3['order_detail_incon'] = '平台抽成';
                $listData3['user_id'] = $info['order_jms_user'];
                $listData3['order_detail_price'] = $price3;
                $listData3['order_id'] = $info['order_id'];
                $listData3['order_detail_type'] = 2;
                $listData3['order_detail_ymd'] = $info['order_fb_ymr'];
                $listData3['oder_detail_ym'] = $info['order_fb_ym'];
                Db::table('up_order_detail')->insertGetId($listData3);


                //插入司机钱包明细
                $order_number = date('YmdHis') . str_pad(mt_rand(1, 99999999), 6, '0', STR_PAD_LEFT).$info['order_dirver_user'];
                $user_real_name = Db::table('up_u_user')
                    ->where('user_id',$info['order_jms_user'])
                    ->value("user_real_name");
                $data1['user_id'] = $info['order_dirver_user'];
                $data1['balance_type'] = 3;
                $data1['balance_time'] = date('Y-m-d H:i:s');
                $data1['balance_title'] = "收到加盟商".($user_real_name).'支付运费';
                $data1['balance_num'] = $order_number;
                $data1['balance_price'] = $info['order_dzxy_freight'];
                $data1['balance_status'] = 2;
                $data1['balance_jia_jian'] = 1;
                $data1['balance_xs'] = 1;
                Db::table('up_user_balance')->insertGetId($data1);
                //定金
                $data4['user_id'] = $info['order_dirver_user'];
                $data4['balance_type'] = 3;
                $data4['balance_time'] = date('Y-m-d H:i:s');
                $data4['balance_title'] = $go_sheng.$go_shi.'--'.$to_sheng.$to_shi.'订单定金返还';
                $data4['balance_num'] = $order_number;
                $data4['balance_price'] = $info['order_dzxy_yf'];
                $data4['balance_status'] = 2;
                $data4['balance_jia_jian'] = 1;
                $data4['balance_xs'] = 1;
                Db::table('up_user_balance')->insertGetId($data4);

                //更新司机,加盟商余额,运费+定金
                $money = $info['order_dzxy_freight']+$info['order_dzxy_yf'];
                Db::table('up_u_user')->where('user_id',$info['order_dirver_user'])->setInc('user_balance',$money);
                //插入加盟商钱包明细
                $order_number1 = date('YmdHis') . str_pad(mt_rand(1, 99999999), 6, '0', STR_PAD_LEFT).$info['order_jms_user'];
                $user_real_name1 = Db::table('up_u_user')
                    ->where('user_id',$info['order_dirver_user'])
                    ->value("user_real_name");
                $data2['user_id'] = $info['order_jms_user'];
                $data2['balance_type'] = 2;
                $data2['balance_time'] = date('Y-m-d H:i:s');
                $data2['balance_title'] = "支付司机".($user_real_name1).'支付运费';
                $data2['balance_num'] = $order_number1;
                $data2['balance_price'] = $info['order_dzxy_freight'];
                $data2['balance_status'] = 2;
                $data2['balance_jia_jian'] = 2;
                $data2['balance_xs'] = 2;
                Db::table('up_user_balance')->insertGetId($data2);
                //更新加盟商余额,运费
                Db::table('up_u_user')->where('user_id',$user_id)->setDec('user_balance',$info['order_dzxy_freight']);
            }
            Db::commit();
            return json(['status'=>200,'msg'=>"支付成功"]);
        }catch (\Exception $e) {
            Db::rollback();
            return json(['status'=>100,'msg'=>"支付失败"]);
        }
    }
    //询价单-发送运费
    public function sendPrice(){
        $order_id = input('param.order_id');
        $data['order_freight'] = input('param.money');
        $data['send_date'] = date('Y-m-d H:i:s');
        $res = Db::table('up_order')->where('order_id',$order_id)->update($data);
        if($res){
            return json(['status'=>200,'msg'=>"发送成功"]);
        }else{
            return json(['status'=>100,'msg'=>"发送失败"]);
        }
    }

    //正常单-加盟商拒绝
    public function jueOrder(){
        extract(input());
        $order_id = input('param.order_id');
        $content = input('param.content');
        $data['order_jujue_intro'] =$content;
        $data['order_type'] =3;
        $res = Db::table('up_order')->where('order_id',$order_id)->update($data);
        $list =Db::table('up_order')->where('order_id',$order_id)->find();
        //查询地区
        $go_sheng = Db::table('up_area')->where('district_id',$list['order_go_sheng'])->value('district');
        $to_sheng = Db::table('up_area')->where('district_id',$list['order_to_sheng'])->value('district');
        if($res){
            $dataList['n_title'] ='您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请核查订单';
            $dataList['n_type'] =  2;
            $dataList['n_notice_type'] = 2;
            $dataList['n_user_id'] = ','.$list['order_qy_user'].',';
            $dataList['n_read'] = ',0,';
            $dataList['n_delete'] = ',0,';
            $dataList['n_time'] = date('Y-m-d H:i:s');
            $dataList['n_status'] = 2;
            Db::table('up_notice')->insertGetId($dataList);
            //推送
            $lists = [];
            $v = (string)$list['order_qy_user'];
//            array_push($lists, $v);

            $code=2;
            $str = array('msg'=>'您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请核查订单','type'=>1,'order_id'=>$order_id);
            $str1 = '您发布的'.$go_sheng.'-'.$to_sheng.'的订单被拒绝，请核查订单';
            //推送司机
            try{
                $this->Jpush2(1, $v, $str1, $str,$code);
            }catch(\Exception $e){

            }
            return json(['status'=>200,'msg'=>'接单成功']);
        }else{
            return json(['status'=>0,'msg'=>'接单失败']);
        }
    }

    public function dot(){
        extract(input());
        $order_id = input('param.order_id');
        $map['order_id'] = $order_id;
        $info = Db::table('up_order_dot')->field('dot_id as id,dot_lon as lon,dot_lat as lat')->where($map)->select();
        return json(['status'=>200,'msg'=>$info]);
    }
}